﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Reflection;

namespace BackupRestore
{
    /// <summary>
    /// Class BackupRestore
    /// </summary>
    static class BackupRestore
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {

            new BackupRestoreController(ParseArgs(args));
        }
        /// <summary>
        /// This method prints the correct usage type and exits program
        /// </summary>
        private static void PrintUsageAndExit()
        {
            Console.WriteLine ("Usage:  BackupRestore [-d DebugLevel]" +
            "\nWhere DebugLevel can be:\n" +
            RunMode.GetDebugModesAsNewLineSeparatedString());
            Environment.Exit(0);
        }
        /// <summary>
        /// takes the arguments passed to the class
        /// if args length = 0, it does no debugging
        /// if args length = 2
        /// arg 1 - program to run in debug mode
        /// arg 2 - debug type
        /// </summary>
        /// <param name="args"></param>
        /// <returns> runMode object </returns>
        private static RunMode ParseArgs(string[] args)
        {
            RunMode runMode = new RunMode();

            if (args.Length == 0)
            {
                runMode.RequestedDebugMode = RunMode.DebugMode.NONE;
                return runMode;
            }

            if (args.Length == 1 || args.Length > 2 || !args[0].Equals("-d") || (args.Length == 2 && !RunMode.IsDebugMode(args[1])))
            {
                PrintUsageAndExit();
            }

            try
            {
                runMode.SetDebugModeFromString(args[1]);
            }
            catch (Exception)
            {
                PrintUsageAndExit();
            }

            return runMode;
            
        }
    }
}
